package multidraw;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.IOException;
import java.util.Vector;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import multidraw.model.DrawingCanvasModel;
import multidraw.model.ModelObserver;
import multidraw.model.commands.ChangeColorCommand;
import multidraw.model.commands.ClearCanvasCommand;
import multidraw.model.commands.SwitchingFillingCommand;
import multidraw.model.commands.TransferControlCommand;



public class ClientListPanelController implements ActionListener, ModelObserver {
	private DrawingCanvasModel myModel;
//	private ControlPanelView myView;
	
	private ClientListPanelView clientListPanel;
	
	// TODO add the clientlistpanelview to the initialization methods
	
	public ClientListPanelController(DrawingCanvasModel model, ClientListPanelView view) {
		this.myModel = model;
		this.clientListPanel = view;
		
	}
	

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub		

		/*
		 * Transfer control event
		 */
		if (e.getSource().equals(clientListPanel.getTransferButton())) {

			JOptionPane.showMessageDialog(null, "Transferred control to " + 
					clientListPanel.getSelectedUser());

			//JOptionPane.showMessageDialog(null, clientListPanel.getSelectedUser());

		    TransferControlCommand cmd = new TransferControlCommand(clientListPanel.getSelectedUser());
		    myModel.addCommand(cmd);
		}
		/*
		 * Revoke event
		 */
		else if (e.getSource().equals(clientListPanel.getRevokeButton())) {
			//JOptionPane.showMessageDialog(null, "Revoked control");
			TransferControlCommand cmd = new TransferControlCommand(myModel.getName());
			myModel.addCommand(cmd);
		}	
		
	}
	
	public void updateContent() {
		
	}
}
